<template>
  <div>
    <el-dialog
      :visible.sync="showDialog"
      append-to-body
      :close-on-click-modal="false"
      @close="close"
      width="50%"
    >
      <el-form
        :inline="true"
        ref="formInline"
        :model="formInline"
        class="demo-form-inline"
        :rules="rules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="询价响应截止日期" prop="endTime">
              <el-input
                v-model.number="formInline.endTime"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="询价有效期" prop="validityPeriod">
              <el-input
                v-model.number="formInline.validityPeriod"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="询价备注" prop="remark">
              <el-input
                type="textarea"
                v-model="formInline.remark"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="close()">取消</el-button>
        <el-button v-noMoreClick @click="submit('formInline')" type="primary">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deepClone } from "@/util/util.js";
export default {
  name: "configDialog",
  data() {
    return {
      formInline: {
        endTime: "",
        validityPeriod: "",
        remark: "",
      },
      showDialog: false,
      callback: () => {},
      form: {},
      rules: {
        endTime: [
          { required: true, message: "不能为空" },
          { type: "number", message: "必须为数字值" },
        ],
        validityPeriod: [
          { required: true, message: "不能为空" },
          { type: "number", message: "必须为数字值" },
        ],
      },
    };
  },
  methods: {
    open(rowdata, { callback }) {
      console.log("bbb", rowdata);
      this.formInline.validityPeriod = Number(rowdata[2].dictValue);
      this.formInline.endTime = Number(rowdata[1].dictValue);
      this.callback = callback;
      this.showDialog = true;
    },
    close() {
      this.$refs.formInline.resetFields();
      this.showDialog = false;
    },

    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.callback(deepClone(this.formInline));
          this.close();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style></style>
